Move path to rustc into Rustc struct
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jul 2016 21:23:12 +0000 (00:23 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 20 Jul 2016 21:23:12 +0000 (00:23 +0300)
src/cargo/util/config.rs
src/cargo/util/rustc.rs

index 28e9228d2db5c0bd71da9416bf860fe87d53e0e9..a225b6cfd1aa3a0a3dc5ebd78c9c7a48f6f529ae 100644 (file)
@@ -28,7 +28,6 @@ pub struct Config {
     values: RefCell<HashMap<String, ConfigValue>>,
     values_loaded: Cell<bool>,
     cwd: PathBuf,
-    rustc: RefCell<Option<PathBuf>>,
     rustdoc: RefCell<Option<PathBuf>>,
     target_dir: RefCell<Option<Filesystem>>,
     extra_verbose: Cell<bool>,
@@ -47,7 +46,6 @@ impl Config {
             cwd: cwd,
             values: RefCell::new(HashMap::new()),
             values_loaded: Cell::new(false),
-            rustc: RefCell::new(None),
             rustdoc: RefCell::new(None),
             target_dir: RefCell::new(None),
             extra_verbose: Cell::new(false),
@@ -99,10 +97,8 @@ impl Config {
     }
 
     pub fn rustc(&self) -> CargoResult<Ref<Path>> {
-        if self.rustc.borrow().is_none() {
-            *self.rustc.borrow_mut() = Some(try!(self.get_tool("rustc")));
-        }
-        Ok(Ref::map(self.rustc.borrow(), |opt| opt.as_ref().map(AsRef::as_ref).unwrap()))
+        let rustc = try!(self.rustc_info());
+        Ok(Ref::map(rustc, |r| r.path.as_ref()))
     }
 
     pub fn rustdoc(&self) -> CargoResult<Ref<Path>> {
@@ -114,8 +110,8 @@ impl Config {
 
     pub fn rustc_info(&self) -> CargoResult<Ref<Rustc>> {
         if self.rustc_info.borrow().is_none() {
-            let path = try!(self.rustc());
-            *self.rustc_info.borrow_mut() = Some(try!(Rustc::new(&*path)));
+            let path = try!(self.get_tool("rustc"));
+            *self.rustc_info.borrow_mut() = Some(try!(Rustc::new(path)));
         }
         Ok(Ref::map(self.rustc_info.borrow(), |opt| opt.as_ref().unwrap()))
     }
index 51039de7acdfb8f5c2275aa7b2ab872b05ae4e6a..8504e51e2633474a818ecda207407632e20a25f2 100644 (file)
@@ -1,8 +1,9 @@
-use std::path::Path;
+use std::path::PathBuf;
 
 use util::{self, CargoResult, internal, ChainError};
 
 pub struct Rustc {
+    pub path: PathBuf,
     pub verbose_version: String,
     pub host: String,
     /// Backwards compatibility: does this compiler support `--cap-lints` flag?
@@ -15,8 +16,8 @@ impl Rustc {
     ///
     /// If successful this function returns a description of the compiler along
     /// with a list of its capabilities.
-    pub fn new<P: AsRef<Path>>(path: P) -> CargoResult<Rustc> {
-        let mut cmd = util::process(path.as_ref());
+    pub fn new(path: PathBuf) -> CargoResult<Rustc> {
+        let mut cmd = util::process(&path);
         cmd.arg("-vV");
 
         let mut first = cmd.clone();
@@ -42,6 +43,7 @@ impl Rustc {
         };
 
         Ok(Rustc {
+            path: path,
             verbose_version: verbose_version,
             host: host,
             cap_lints: cap_lints,